package com.dxc.intern.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dxc.intern.entity.PrimaryScreening;
import com.dxc.intern.entity.Resume;
import com.dxc.intern.mapper.PrimaryScreeningMapper;
import com.dxc.intern.mapper.ResumeMapper;
import com.dxc.intern.service.PrimaryScreeningService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 初筛数据表 服务实现类
 * </p>
 *
 * @author zhangchengming
 * @since 2022-02-21
 */
@Service
public class PrimaryScreeningServiceImpl extends ServiceImpl<PrimaryScreeningMapper, PrimaryScreening> implements PrimaryScreeningService {

    @Autowired
    PrimaryScreeningMapper primaryScreeningMapper;
    @Autowired
    ResumeMapper resumeMapper;

    //获取初筛表的总数量
    @Override
    public int getcount() {
        return primaryScreeningMapper.getCount();
    }

    //通过PrimaryScreening对象添加初筛表
    @Override
    public void addPrimaryScreening(PrimaryScreening primaryScreening) {
        primaryScreeningMapper.insert(primaryScreening);
    }

    //通过id删除初筛表
    @Override
    public void delPrimaryScreening(Integer id) {
        primaryScreeningMapper.deleteById(id);
    }

    //通过PrimaryScreening对象更改初筛表
    @Override
    public void updatePrimaryScreening(PrimaryScreening primaryScreening) {
        primaryScreeningMapper.updateById(primaryScreening);
    }

    //通过
    @Override
    public Page<Resume> fuzzyQuerry(String name, String phone, String source, String education, String postion, String addr, String status, Page<Resume> currentPage) {

        QueryWrapper<Resume> wrapper = new QueryWrapper<>();
        wrapper.like(org.apache.commons.lang3.StringUtils.isNotBlank(name), "name", name)
                .like(org.apache.commons.lang3.StringUtils.isNotBlank(phone), "phone", phone)
                .like(org.apache.commons.lang3.StringUtils.isNotBlank(source), "school", source)
                .eq(org.apache.commons.lang3.StringUtils.isNotBlank(education), "education", education)
                .eq(org.apache.commons.lang3.StringUtils.isNotBlank(postion), "postion", postion)
                .eq(org.apache.commons.lang3.StringUtils.isNotBlank(addr), "addr", addr)
                .eq(StringUtils.isNotBlank(status), "induction_Progress", status);

        Page<Resume> resumePage = resumeMapper.selectPage(currentPage, wrapper);
        return resumePage;
    }

    @Override
    public IPage<Resume> getPrimaryScreening(Long current, Long size, Resume resume) {
        QueryWrapper<Resume> testWrapper = new QueryWrapper<>();
        testWrapper.like("name", "张");

        QueryWrapper<Resume> queryWrapper = new QueryWrapper<>();

//        if (resume != null) {
//            if (resume.getName() != null && !resume.getName().equals(" ")&& !resume.getName().equals(null)) {
//                queryWrapper.like("name", resume.getName());
//            }
//            if (resume.getPhone() != null && !resume.getPhone().equals(" ") && !resume.getPhone().equals(null)) {
//                queryWrapper.like("phone", resume.getPhone());
//            }
//            if (resume.getEducation() != null && !resume.getEducation().equals(" ") && !resume.getEducation().equals(null)) {
//                queryWrapper.like("education", resume.getEducation());
//            }
//            if (resume.getPostion() != null && !resume.getPostion().equals(" ") && !resume.getPostion().equals(null)) {
//                queryWrapper.like("postion", resume.getPostion());
//            }
//            if (resume.getAddr() != null && !resume.getAddr().equals(" ") && !resume.getAddr().equals(null)) {
//                queryWrapper.like("addr", resume.getAddr());
//            }
//            if (resume.getSource() != null && !resume.getSource().equals(" ") && !resume.getSource().equals(null)) {
//                queryWrapper.like("source", resume.getSource());
//            }
//            if (resume.getInductionProgress() != null && !resume.getInductionProgress().equals(null)) {
//                queryWrapper.like("induction_progress", resume.getInductionProgress());
//            }
        System.out.println(resume);
        queryWrapper.like(resume.getName() != null && !resume.getName().equals("") && !resume.getName().equals(null), "name", resume.getName());
        queryWrapper.like(resume.getPhone() != null && !resume.getPhone().equals("") && !resume.getPhone().equals(null), "phone", resume.getPhone());
        queryWrapper.like(resume.getEducation() != null && !resume.getEducation().equals("") && !resume.getEducation().equals(null), "education", resume.getEducation());
        queryWrapper.like(resume.getPostion() != null && !resume.getPostion().equals("") && !resume.getPostion().equals(null), "postion", resume.getPostion());
        queryWrapper.like(resume.getAddr() != null && !resume.getAddr().equals("") && !resume.getAddr().equals(null), "addr", resume.getAddr());
        queryWrapper.like(resume.getSource() != null && !resume.getSource().equals("") && !resume.getSource().equals(null), "source", resume.getSource());
        queryWrapper.like(resume.getInductionProgress() != null && !resume.getInductionProgress().equals(null), "induction_progress", resume.getInductionProgress());
        return resumeMapper.selectPage(new Page<Resume>(current, size), queryWrapper);
    }


}
